#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.device.rabbit.consume;

import com.alibaba.fastjson.JSON;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import ${package}.device.rabbit.event.DeviceNotifyRabbitEvent;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@ConditionalOnProperty(prefix = "spring.rabbitmq", name = "enable", havingValue = "true")
public class DeviceRabbitConsumer {

    @RabbitListener(queues = "rabbit.test", containerFactory = "manualContainerFactory")
    public void actionExe(Message message, Channel channel, DeviceNotifyRabbitEvent deviceNotifyRabbitEvent) {
        log.info("msg：{}", JSON.toJSONString(deviceNotifyRabbitEvent));
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (Exception e) {
            log.error("消费消息失败：{}", deviceNotifyRabbitEvent.getDeviceId(), e);
        }
    }
}
